home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / midi / hip211.lha / Support / HippoPlay.filer < prev    next >
Text File  |  1994-05-27  |  17KB  |  438 lines

  1. /* HippoPlayer ARexx script for Filer, use as a button.     (v 1.0) *
  2.  * ================================================================ *
  3.  *                                                                  *
  4.  * Adds selected files into HiP's playlist and randomplays them.    *
  5.  * If HiP isn't already running it is run first.                    *
  6.  *                                                                  *
  7.  * If directories were selected this script recurses through all    *
  8.  * subdirectories, so it is possible to add all your modules to     *
  9.  * HiP's playinglist just by selecting your module directory!       *
  10.  *                                                                  *
  11.  * If nothing was selected (user just pushed the button) then       *
  12.  * we tell HiP to Random Play with it's current playlist unless     *
  13.  * there's only one module in it, in which case we eject it.        *
  14.  * But if the playlist is empty already we advice the user to       *
  15.  * select a module before fooling around...                         *
  16.  *                                                                  *
  17.  *------------------------------------------------------------------*
  18.  * NOTE! This script checks if a file has a suffix or prefix that   *
  19.  * indicates something else than a module, for example "foo.info",  *
  20.  * "program.readme" or ".backdrop". Unfortunately this also makes   *
  21.  * the script noticeably slower, so this feature is disabled by     *
  22.  * default. If you want to use it, see CONFIGURATION below.         *
  23.  *------------------------------------------------------------------*
  24.  *                                                                  *
  25.  ***** Requirements: rexxsupport.library, HiP, and Filer...    ******
  26.  * Remember to replace the HippoPath variable below with the        *
  27.  * correct path of HiP in your system! You might also want to set   *
  28.  * HiP's screen to FilerScreen in the HiP-prefs, though this script *
  29.  * opens HiP on FilerScreen automatically anyway.                   *
  30.  *                                                                  *
  31.  * Sorry for the messyness, especially in dirpart, but it works! :) *
  32.  * If it fails for you, contact me:                                 *
  33.  * Janne Simonen - jsimonen@cc.joensuu.fi                           */
  34.  
  35.  
  36. /* -------------------------------------------------------------------- */
  37. /**** CONFIGURATION: change the following lines to suit your system! ****/
  38. /* -------------------------------------------------------------------- */
  39.  
  40. HippoPath = 'dh2:HippoPlayer/Hip'               /* Where to find HiP    */
  41.  
  42. /* This flag controls the printing of extra information on FilerScreen. */
  43. /* 0 = OFF, 1 = ON. If you don't have composers' names in filenotes and */
  44. /* don't want to know how big the mod is, switch this off.              */
  45.  
  46. Verbose = 1                                     /* Default: speak up!   */
  47.  
  48. /* This flag turns filename checking on/off, 0 = OFF, 1 = ON    */
  49.  
  50. CheckFileNames = 0  /* Default: don't check filenames for ".info"s etc. */
  51.  
  52. /* These suffixes/prefixes indicate that a file really is NOT a module! */
  53. /* You can add your own, just remember to change crapnumbers accordingly*/
  54. /* The more you add, the slower the script gets, so...                  */
  55.  
  56. IF ~(CheckFileNames = 0) THEN DO    /* if checking is not disabled  */
  57.  
  58.     crapsufnumber = 3               /* number of crap suffixes  */
  59.     crapsuffix.1 = '.info'          /* disregard these suffixes */
  60.     crapsuffix.2 = '.readme'
  61.     crapsuffix.3 = '.doc'
  62.  
  63.     crapprefnumber = 1              /* number of crap prefixes  */
  64.     crapprefix.1 = '.'              /* disregard these prefixes */
  65. END
  66.  
  67. ELSE DO         /* if checking is disabled then accept ALL files    */
  68.     crap = 0    /* regardless of filename. Don't change this!       */
  69. END
  70.  
  71. /* Random play if nothing selected? If not then show modinfo    */
  72.  
  73. RandPlay = 0
  74.  
  75.  
  76. /* -------------------------------------------------------------------- */
  77. /* ******************* MAIN PROGRAM STARTS HERE *********************** */
  78. /* -------------------------------------------------------------------- */
  79.  
  80. OPTIONS RESULTS
  81.  
  82. SIGNAL ON IOERR    /* Trap for IO-Errors (filehandling etc.)    */
  83. SIGNAL ON BREAK_C  /* Trap for control-c break (doesn't work?)  */
  84.  
  85. /********** Make sure HiP is running (with an open ARexx port) **********/
  86.  
  87. IF ~SHOW("Ports","HIPPOPLAYER") THEN DO
  88.     ADDRESS 'FilerRexx'
  89.     'STATUS Loading HippoPlayer...'
  90.     ADDRESS 'COMMAND' 'run >NIL: '||HippoPath
  91.     
  92.     /* give HiP exactly 5 seconds time to emerge */
  93.     ADDRESS 'FilerRexx'
  94.     'STATUS Waiting for HippoPlayer to open its ARexx port...'
  95.     TIME('R')
  96.     DO WHILE ((TIME('E')<5) & (~SHOW("Ports","HIPPOPLAYER")))
  97.     END
  98.     
  99.     IF ~SHOW("Ports","HIPPOPLAYER") THEN DO
  100.         ADDRESS 'FilerRexx'
  101.         "STATUS HippoPlayer didn't show up!"
  102.         EXIT
  103.     END
  104.  
  105.     ADDRESS 'HIPPOPLAYER'
  106.     'PUBSCREEN FilerScreen'     /* open HiP on FilerScreen  */
  107.     'ZIP 0'                     /* and zip the window.      */
  108. END
  109.  
  110. /****** Open a lib to get SHOWDIR() to be used with directories  ********/
  111.  
  112. CALL ADDLIB('rexxsupport.library', 0, -30, 0)
  113.  
  114. /********************* Give HiP the modules to play *********************/
  115.  
  116. ADDRESS 'FilerRexx'
  117.  
  118. /* Get source directory name, append "/" if it is not a device name     */
  119. GETSOURCEPATH
  120. srcdir = RESULT
  121. IF RIGHT( srcdir, 1 ) ~= ":" THEN srcdir = srcdir || "/"
  122.  
  123. GETNUMENTRIES                   /* get number of sourcedir entries  */
  124. numentries = RESULT
  125.  
  126. DO j = 1 TO numentries          /* loop through all entries         */
  127.   GETNAME j                     /* get jth entry                    */
  128.   entry = RESULT
  129.  
  130.   type = LEFT( entry, 1 )       /* parse filetype (f, d, F, D)      */
  131.   name = SUBSTR( entry, 2 )     /* parse filename                   */
  132.  
  133.   SELECT                        /* it's either a file OR a directory*/
  134.  
  135.     /* If entry is a selected FILE we add it to playlist            */
  136.  
  137.     WHEN type = 'f' THEN DO
  138.  
  139.       IF CheckFileNames = 1 THEN DO     /* if checking not disabled     */
  140.         CALL FileCheck                  /* check if it's a module       */
  141.       END
  142.  
  143.       IF crap = 0 THEN DO               /* if it is, then lets add...   */
  144.  
  145.         IF checkflag ~= 'TRUE' THEN DO  /* if it's the first file to    */
  146.           ADDRESS 'HIPPOPLAYER'         /* add we clear the playlist    */
  147.           'CLEAR'
  148.           checkflag = 'TRUE'
  149.         END
  150.  
  151.         ADDRESS 'FilerRexx'
  152.                                         /* just finetuning the message..*/
  153.         Message = 'HiP: Adding module "'||name||'" into playlist...'
  154.         IF LENGTH( Message ) < 67 THEN DO
  155.           Message = OVERLAY( 'Please wait!', Message, 68)
  156.         END
  157.  
  158.         'STATUS '||Message              /* tell user what's happening   */
  159.         ADDRESS 'HIPPOPLAYER'
  160.         'ADD '||srcdir||name            /* add the file into playlist   */
  161.  
  162.       END /* IF - FileCheck   */
  163.  
  164.       ADDRESS 'FilerRexx'
  165.       TOGGLEENTRY j                     /* de-select                    */
  166.  
  167.     END /* WHEN */
  168.  
  169.     /* If entry is a DIRECTORY we scan it through and see what's in     */
  170.  
  171.     WHEN type = 'd' THEN DO
  172.  
  173.       Dirname = srcdir||name
  174.       /* get a string containing the filenames separated with a '0a'x   */
  175.       Filelist = SHOWDIR( Dirname, 'FILE', '0a'x )
  176.       /* if string not empty we append a '0a'x (to make things work...) */
  177.       IF Filelist ~= '' THEN Filelist = Filelist || '0a'x
  178.  
  179.       CALL FileNameParser   /* add all the files in the dir to playlist */
  180.  
  181.       /* See if there are any SUBDIRECTORIES and scan them for files    */
  182.  
  183.       i = 1                                         /* recursion level  */
  184.       CALL DirRecurser      /* let's delve through the subdirectories   */
  185.       ADDRESS 'FilerRexx'
  186.       TOGGLEENTRY j
  187.  
  188.     END /* WHEN - DIRECTORY */
  189.  
  190.     OTHERWISE                   /* ignore entries not selected          */
  191.  
  192.   END /* SELECT */
  193.  
  194. END /* DO j */
  195.  
  196. /* -------------------------------------------------------------------- */
  197. /* Ok, we've scanned all selected files/dirs and added the files to     */
  198. /* playlist, now it's time to do some bonus stuff...                    */
  199. /* -------------------------------------------------------------------- */
  200.  
  201. /* If no file (or module! FileNameCheck...) was selected then:          */
  202.  
  203. IF checkflag ~= "TRUE" THEN DO
  204.  
  205.     ADDRESS 'HIPPOPLAYER'
  206.     'GET NFIL'                    /* get number of files in playlist    */
  207.     numberoffiles = RESULT
  208.  
  209.     /* if only non-module files were selected then this helps us complain */
  210.     IF NameCheckFlag = 1 THEN numberoffiles = 0
  211.  
  212.     IF numberoffiles = 1 THEN DO  /* if it's one we eject the mod       */
  213.         'CLEAR'
  214.         'EJECT'
  215.         ADDRESS 'FilerRexx'
  216.         'STATUS HiP: Ejected the only module in the playlist.'
  217.         EXIT
  218.     END
  219.  
  220.     IF numberoffiles = 0 THEN DO  /* Nothing playing? Let's complain    */
  221.         ADDRESS 'FilerRexx'
  222.         'STATUS HiP: It might help if you selected a module to play! :)'
  223.         EXIT
  224.     END
  225.  
  226.     IF RandPlay = 0 THEN
  227.         CALL DisplayStuff   /* Show info if multiple entries in playlist*/
  228.  
  229. END
  230.  
  231. ADDRESS 'FilerRexx'
  232. 'STATUS HiP: Loading module, please wait...'
  233.  
  234. ADDRESS 'HIPPOPLAYER'
  235.  
  236. 'GET NFIL'                          /* get number of files in playlist  */
  237.                                     /* because RANDPLAY doesn't work    */
  238. IF RESULT = 1 THEN DO               /* if there's only one file...      */
  239.     'CHOOSE 1'                      /* ...at least not with HiP207.     */
  240.     'PLAY'
  241. END                                 /* single file: let's play it.      */
  242. ELSE 'RANDPLAY'                     /* multiple files: Random Play.     */
  243.  
  244. 'GET PLAY'                          /* check if anything is playing     */
  245. playornot = RESULT
  246. IF playornot = 0 THEN DO            /* if not -> we're very sorry...    */
  247.     ADDRESS 'FilerRexx'             /* ...probably out of memory        */
  248.     "STATUS HiP: Sorry, can't play this one!"
  249.     EXIT
  250. END
  251.  
  252. DisplayStuff:
  253. /* Now a mod is playing, so we just display some info on FilerScreen    */
  254.  
  255. 'GET NAME'                          /* get mod name so that we can show */
  256. modname = RESULT                    /* it on Filer's statusbar          */
  257.  
  258. IF modname = '' THEN DO             /* if modname doesn't exist         */
  259.     'GET CNAM'                      /* we simply use filename           */
  260.     modname = RESULT
  261.                                     /* strip off any prefix (like mod.) */
  262.     /* a little fix for a bug in HiP207: CNAM gives path too! K-P? :)   */
  263.     DivPos = max(lastpos(':', modname),lastpos('/', modname)) +1
  264.     modname = substr(modname, DivPos)
  265.     modname = substr(modname, lastpos('.', modname, 6) +1)
  266.  
  267. END /* IF */
  268.  
  269. modname = SPACE( modname, 1)        /* remove extra spaces from name    */
  270.  
  271. IF Verbose = 0 THEN DO              /* if Verbose is switched off we    */
  272.     ADDRESS 'FilerRexx'             /* only tell the module's name      */
  273.     'STATUS HiP: Playing "'||modname'"'
  274.     EXIT                            /* and exit.*/
  275. END
  276.  
  277. 'GET COMM'                          /* get filenote/comment because     */
  278. comment = RESULT                    /* I have the composer's name in it */
  279.  
  280. IF comment = '' THEN DO             /* no comment? Then give type&size  */
  281.     'GET TYPE'                      /* instead to have some chrome :)   */
  282.     modtype = RESULT
  283.     'GET SIZE'
  284.     modsize = RESULT
  285.  
  286.     comment = 'HiP: Playing '||modtype||' module "'||modname'"'
  287.  
  288.                             /* check that announcement fits on screen   */
  289.     IF LENGTH( comment ) < 61 THEN DO
  290.         comment = comment || ', size '||modsize||' bytes'
  291.     END
  292.                                     /* announce what HiP is playing     */
  293.     ADDRESS 'FilerRexx'             /* with modtype and modsize         */
  294.     'STATUS ' || comment
  295.  
  296. END /* IF */
  297.  
  298. ELSE DO
  299.     comment = 'by ' || comment      /* announce with composer's name    */
  300.     ADDRESS 'FilerRexx'
  301.     'STATUS HiP: Playing "'||modname||'" '||comment
  302. END /* ELSE */
  303.  
  304. EXIT                                /* voilá! */
  305.  
  306.  
  307. /* -------------------------------------------------------------------- */
  308. /*************** END OF MAIN PROGRAM, SUBROUTINES FOLLOW ****************/
  309. /* -------------------------------------------------------------------- */
  310.  
  311.  
  312. FileNameParser:
  313. /* Parses filenames from the string 'Filelist' and adds them to playlist*/
  314. /* Gets the complete path from the variable 'Dirname'.                  */
  315. /* Filelist looks like "file1'0a'xfile2'0a'xfile3'0a'xfile4'0a'x".      */
  316.  
  317.  DO WHILE POS( '0a'x, Filelist ) > 0    /* while we still have files    */
  318.  
  319.     Slashpos = POS( '0a'x, Filelist )   /* find the next separator      */
  320.     name = LEFT( Filelist, Slashpos -1) /* extract filename             */
  321.  
  322.     IF CheckFileNames = 1 THEN DO
  323.       CALL FileCheck                    /* see if it is a module        */
  324.     END
  325.  
  326.     IF crap = 0 THEN DO                 /* if yes, add it to playlist:  */
  327.  
  328.       IF checkflag ~= 'TRUE' THEN DO    /* if this is the first file    */
  329.           ADDRESS 'HIPPOPLAYER'         /* to add to playlist then      */
  330.           'CLEAR'                       /* clear the list first         */
  331.           checkflag = 'TRUE'
  332.       END
  333.  
  334.       ADDRESS 'FilerRexx'
  335.                                         /* just finetuning the message..*/
  336.       Message = 'HiP: Adding module "'||name||'" into playlist...'
  337.       IF LENGTH( Message ) < 67 THEN DO
  338.           Message = OVERLAY( 'Please wait!', Message, 68)
  339.       END
  340.  
  341.       'STATUS '||Message
  342.       ADDRESS 'HIPPOPLAYER'
  343.       'ADD '||Dirname||'/'||name        /* add the mod to playlist      */
  344.  
  345.     END /* IF - FileCheck */
  346.                                 /* Strip out added filename from string */
  347.     Filelist = SUBSTR( Filelist, Slashpos +1)
  348.  
  349.  END /* WHILE */
  350.  
  351. RETURN /* END OF SUBROUTINE ----------------------------------------*/
  352.  
  353.  
  354. DirRecurser:
  355. /* Recurses through all the subdirectories of a directory, then     */
  356. /* calls FileNameParser to add the files in them into playlist.     */
  357.  
  358. /* Get list of subdirectories                                       */
  359. Dirlist.i = SHOWDIR( Dirname, 'DIR', '0a'x)
  360. IF Dirlist.i ~= '' THEN Dirlist.i = Dirlist.i || '0a'x
  361.  
  362. /* Go through the subdirs one by one, adding any files to playlist  */
  363. DO WHILE POS( '0a'x, Dirlist.i ) > 0
  364.  
  365.     Slashpos = POS( '0a'x, Dirlist.i )          /* find the divider */
  366.     dname = LEFT( Dirlist.i, Slashpos -1)       /* get subdirname   */
  367.     Dirlist.i = SUBSTR( Dirlist.i, Slashpos +1) /* strip it off     */
  368.  
  369.     Dirnamebak.i = Dirname                /* take backup of Dirname */
  370.     Dirname = Dirname || '/' ||dname      /* make subdirectorypath  */
  371.  
  372.     Filelist = SHOWDIR( Dirname, 'FILE', '0a'x)    /* make filelist */
  373.     IF Filelist ~= '' THEN Filelist = Filelist || '0a'x
  374.  
  375.     CALL FileNameParser     /* add any files in subdir to playlist  */
  376.  
  377.     i = i + 1                           /* increase recursion level */
  378.  
  379.     CALL DirRecurser        /* call subroutine itself recursively   */
  380.  
  381.     i = i - 1                           /* decrease recursion level */
  382.  
  383.     Dirname = Dirnamebak.i              /* get back saved Dirname   */
  384. END
  385.  
  386. RETURN  /* END OF SUBROUTINE -----------------------------------*/
  387.  
  388.  
  389. FileCheck:
  390. /* Checks if file clearly is not a module (.info .readme...)    */
  391. /* Gets the filename from a global variable called "name"       */
  392. /* If file is not a mod, returns crap = 1, else returns crap=0. */
  393. /* Bad suf(/pre)fixes are stored in crapsuf(/pre)fix variable.  */
  394.  
  395. a = 1
  396.  
  397. DO WHILE a < (crapsufnumber+1)
  398.     /* Check suffix */
  399.     IF RIGHT( name, LENGTH( crapsuffix.a ) ) = crapsuffix.a THEN DO
  400.         crap = 1            /* file is not a module!        */
  401.         NameCheckFlag = 1   /* a non-module file was found  */
  402.         RETURN
  403.     END
  404.     a = a + 1
  405. END
  406.  
  407. a = 1
  408.  
  409. DO WHILE a < (crapprefnumber+1)
  410.     /* Check prefix */
  411.     IF LEFT( name, LENGTH( crapprefix.a ) ) = crapprefix.a THEN DO
  412.         crap = 1            /* file is not a module!    */
  413.         NameCheckFlag = 1   /* a non-mod was selected   */
  414.         RETURN
  415.     END
  416.     a = a + 1
  417. END
  418.  
  419. crap = 0    /* file passed the check - it's no crap! :) */
  420.  
  421. RETURN      /* END OF SUBROUTINE -------------------------------*/
  422.  
  423.  
  424. IOERR:      /* I/O-Error trap, not tested, might even work...   */
  425.  
  426. ADDRESS 'FilerRexx'
  427. 'STATUS HiP: Sorry, an I/O-error has occurred on line '||SIGL||'!'
  428. 'ALERTBOX I/O error - something is wrong!|File "'||name||'" was being processed.'
  429. EXIT
  430.  
  431.  
  432. BREAK_C:    /* Break trap, never had this work...   */
  433.  
  434. ADDRESS 'FilerRexx'
  435. "STATUS HiP: Break request detected - I won't play anything!"
  436. 'NONE'
  437. EXIT
  438.